USE [master]
GO

/****** Object:  UserDefinedFunction [dbo].[GetVDBAAlert]    Script Date: 08/28/2014 12:00:24 ******/
SET ANSI_NULLS OFF
GO

SET QUOTED_IDENTIFIER OFF
GO


/****** Object:  UserDefinedFunction [dbo].[GetVDBAAlert]    Script Date: 08/28/2014 13:39:56 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GetVDBAAlert]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
DROP FUNCTION [dbo].[GetVDBAAlert]
GO

CREATE FUNCTION [dbo].[GetVDBAAlert](@AlertTxt VARCHAR(100), @AlertNum SMALLINT)
RETURNS VARCHAR(4000)
AS
BEGIN
	--Inputs: (Text of alert - Varchar(100), VDBA alert number - SmallInt)
	--Returns Formated VDBA ms_alerts INFO file text 
	DECLARE 
	@Alert_out VARCHAR(400),
	@dt varchar(30),
	@Mail_Id varchar(255)


	SET @Mail_Id = master.dbo.GetMail()
	SET @dt = CONVERT(varchar(30),GETDATE(),121)
	SET @dt = LEFT(@dt,LEN(@dt) - 4)
	SET @dt = RTRIM(LTRIM(@dt))
	 
	SET @Alert_out = dbo.GetVDBAHeader('INFO')+ CHAR(13)+CHAR(10)+
	'ms_alerts|'+RTRIM(LTRIM(@AlertTxt))+'|'+CAST(@AlertNum AS VARCHAR(4))+'|'+@dt + '|' + @Mail_Id + '|'
	RETURN (@Alert_out)
END
GO


